package com.zt.controller;


import com.zt.domain.User;
import jakarta.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.utils.ip.IpUtils;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.zt.dto.WechatLoginDTO;
import com.zt.service.WechatLoginService;
import com.zt.vo.WechatLoginVO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 微信登录接口1
 */
@RestController
@RequestMapping("/wechat")
@Api(tags = "微信登录接口")
public class WechatLoginController extends BaseController {
    
    @Autowired
    private WechatLoginService wechatLoginService;
    
    /**
     * 微信授权登录
     */
    @PostMapping("/login")
    @ApiOperation("微信授权登录")
    public AjaxResult login(@RequestBody WechatLoginDTO loginDTO,HttpServletRequest request) {
        String ip = IpUtils.getIpAddr(request);
        WechatLoginVO loginVO = wechatLoginService.wechatLogin(loginDTO, ip);
        return AjaxResult.success("登录成功", loginVO);
    }


    @PostMapping("/updateUserInfo")
    public AjaxResult updateUserInfo(@RequestBody User userInfo) {
        System.out.println(userInfo);
        // 更新用户信息
        Boolean aBoolean = wechatLoginService.updateUserInfo(userInfo);
        if (aBoolean) {
            return AjaxResult.success("更新成功");
        } else {
            return AjaxResult.error("更新失败");
        }
    }
} 